﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRasta.Configuration;
using OpenRasta.Web;
using uREST.Core;
using uREST.Core.Services;
using uREST.Core.Resources;
using uREST.Core.Codecs;
using uREST.CMS.Resources;
using uREST.CMS.Handlers;

namespace uREST.CMS.Services
{
    public class MemberService : IuRESTService
    {
        public EndPoint EndPoint
        {
            get
            {
                return new EndPoint
                {
                    Name = "Member Service",
                    Description = "",
                    Href = typeof(List<Member>).CreateUri("MemberList").ToString()
                };
            }
        }

        public void RegisterHandlers()
        {
            ResourceSpace.Has.ResourcesOfType<List<Member>>()
                .AtUri(uRESTConfig.BaseUrl + "/members").Named("MemberList")
                .And.AtUri(uRESTConfig.BaseUrl + "/members?username={username}").Named("MemberList")
                .And.AtUri(uRESTConfig.BaseUrl + "/members?role={role}").Named("MemberList")
                .And.AtUri(uRESTConfig.BaseUrl + "/members?membertypealias={memberTypeAlias}").Named("MemberList")
                .HandledBy<MemberHandler>()
                .TranscodedBy<JsonNetCodec>();

            ResourceSpace.Has.ResourcesOfType<Member>()
               .AtUri(uRESTConfig.BaseUrl + "/members/{id}").Named("Member")
               .And.AtUri(uRESTConfig.BaseUrl + "/members/{username}").Named("Member")
               .HandledBy<MemberHandler>()
               .TranscodedBy<JsonNetCodec>();
        }
    }
}
